var newsTable1;
//获取广告信息
function getAdvertising2() {
	if (typeof newsTable1!== 'undefined') {
		newsTable1.fnPageChange('first');
		//getAdvertising2();
		return;
	}
    var i = 1;
    newsTable1 = $("#zskList").DataTable({
        "sAjaxSource": _path + "/zsk/list",
        "fnServerParams": function (aoData) {
            aoData.push(
                { 
                	"name": "typeid",
                	"value": $("#typeid").val() 
                },{
					"name" : "title",
					"value" : $("#title").val()
				}
            );
        },
        "sServerMethod": "POST",
        "sAjaxDataProp": "dataList",
        "fnCreatedRow": function () {
            i++;
        },
        "fnPreDrawCallback": function () {
            i = 1;
        },
        "aoColumns": [
            { "sTitle": "序号", "sWidth": "2%",
                "mData": function () {
                    return i;
                }
            },
	        { "sTitle": "访问量", "mData": "article_read_num", "sWidth": "10%" },
	        { "sTitle": "名称", "mData": "article_title", "sWidth": "10%" },
            //{ "sTitle": "图片", "mData": "imgUrl", "sWidth": "10%" },
//            { "sTitle": "链接", "mData": "url", "sWidth": "10%" },
            { "sTitle": "类别", "mData": "typeid", "sWidth": "10%" ,
            	 "mRender": function (data) {
                     var advertisingType = '';
                  
                     $("#typeid > option").each(function() {  
                    	
                         if ($(this).val() == data) {  
                        	 advertisingType=$(this).text();
                             }  
                         });  
                     if(data==0||data==''){
                    	 advertisingType="未知"
                     }
                     return advertisingType;
                 }
            
            },
            { "sTitle": "操作", "sWidth": "10%",
                "mData": function (data) {
                		var status = '<a href="javascript:;" class="btn default btn-xs purple"'
                		+'tname="'+data.article_title+'" atent="'+data.article_content+'"   turl="http://www.pufayun.cn/app/index.php?i=110&c=entry&do=lawrow&m=legal_cplatform2&id='+data.id+'"  timg="http://www.falvweiyun.com/attachment/'+data.img+'" '
                		+'onclick="addzsk(this)"><i class="fa fa-edit" title="添加一条">添加一条</i></a>';
                		
                        return status;
                }
            }
        ]
    });
}


function addzsk(em){

	
	var lid=$("#lid").val();
	  $.ajax({
          url: _path + '/communication/zskSave',
          type: 'POST',
          data: {
              "name": $(em).attr("tname"),
              "url": $(em).attr("turl"),
              "imgUrl": $(em).attr("timg"),
              "context": $(em).attr("atent"),
               "liveId": lid
          },
          datatype: "josn",//"xml", "html", "script", "json", "jsonp", "text".
          success: function(resp) {
        	if(resp.msg=='200'){
        		alert("添加成功");
        		getAdvertising(lid);
        	}else{
        		alert("添加失败");
        	}
        	}
      });
	
}
